package subject_set.interview.Day3_25_meituan; /**
 * @author haomin
 * @date 2023/03/25 20:11
 **/
import java.util.*;

public class Main3{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine().trim());
        String[] str1 = in.nextLine().trim().split(" ");
        int[] arr1 = new int[n];
        for(int i = 0; i < n; ++i) {
            arr1[i] = Integer.parseInt(str1[i]);
        }

        int max = 0;
        int allSum = 0;
        for(int i : arr1) allSum += i;
        System.out.println(allSum);
        for(int i = 2; i < arr1.length-2; ++i) {
            int sum = 0;
            if(i-2 >= 0) sum += arr1[i-2];
            if(i-1 >= 0) sum += arr1[i-1];
            if(i+2 < arr1.length) sum += arr1[i+2];
            if(i+1 < arr1.length) sum += arr1[i+1];

            max = Math.max(max, allSum-sum);
            System.out.println(max);
        }
        System.out.println(max);
    }
}